﻿using System;
using System.Data;
using System.Windows.Forms;

namespace APP.HELPER.Utils.Net
{
    public class clsEmailOption
    {
        private string string_0;
        private int int_0;
        private bool bool_0;
        public string Host
        {
            get
            {
                return this.string_0;
            }
            set
            {
                this.string_0 = value;
            }
        }
        public int Port
        {
            get
            {
                return this.int_0;
            }
            set
            {
                this.int_0 = value;
            }
        }
        public bool EnableSSL
        {
            get
            {
                return this.bool_0;
            }
            set
            {
                this.bool_0 = value;
            }
        }
        public clsEmailOption()
        {
            try
            {
                this.string_0 = clsEmailOption.CheckOption("Host");
                this.int_0 = Convert.ToInt32(clsEmailOption.CheckOption("Port"));
                this.bool_0 = Convert.ToBoolean(clsEmailOption.CheckOption("EnableSSL"));
            }
            catch
            {
                this.string_0 = "smtp.gmail.com";
                this.int_0 = 587;
                this.bool_0 = true;
            }
        }
        public static string CheckOption(string FieldName)
        {
            string result;
            try
            {
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(Application.StartupPath + "\\Layout\\emailOption.xml");
                result = dataSet.Tables[0].Rows[0][FieldName].ToString();
            }
            catch
            {
                result = "";
            }
            return result;
        }
        public void SaveOption()
        {
            DataSet dataSet = new DataSet();
            using (DataTable dataTable = new DataTable())
            {
                dataTable.Columns.Add("Host", typeof(string));
                dataTable.Columns.Add("Port", typeof(string));
                dataTable.Columns.Add("EnableSSL", typeof(string));
                object[] array = new object[]
				{
					this.string_0.ToString(),
					this.int_0.ToString(),
					this.bool_0.ToString()
				};
                dataTable.Rows.Add(new object[0]);
                dataTable.Rows[0][0] = array[0];
                dataTable.Rows[0][1] = array[1];
                dataTable.Rows[0][2] = array[2];
                dataSet.Tables.Add(dataTable);
            }
            try
            {
                dataSet.WriteXml(Application.StartupPath + "\\Layout\\emailOption.xml");
            }
            catch
            {
            }
        }
        public static void SaveOption(string Host, string Port, string EnableSSL)
        {
            DataSet dataSet = new DataSet();
            using (DataTable dataTable = new DataTable())
            {
                dataTable.Columns.Add("Host", typeof(string));
                dataTable.Columns.Add("Port", typeof(string));
                dataTable.Columns.Add("EnableSSL", typeof(string));
                object[] array = new object[]
				{
					Host.ToString(),
					Port.ToString(),
					EnableSSL.ToString()
				};
                dataTable.Rows.Add(new object[0]);
                dataTable.Rows[0][0] = array[0];
                dataTable.Rows[0][1] = array[1];
                dataTable.Rows[0][2] = array[2];
                dataSet.Tables.Add(dataTable);
            }
            try
            {
                dataSet.WriteXml(Application.StartupPath + "\\Layout\\emailOption.xml");
            }
            catch
            {
            }
        }
    }
}
